package org.bistu.course.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bistu.course.bean.Student;

@Mapper
public interface StudentMapper {
	
	@Select("SELECT id,name,age,sex,createdate,updatadate FROM student")
	List<Student> findAll();

	@Insert("INSERT INTO student(name,age,sex,createdate,updatadate)VALUES(#{name}, #{age}, #{sex}, now(), now())")
	void addStudent(Student student);

	@Update("UPDATE student SET name=#{name}, age=#{age}, sex=#{sex}, updatadate=now() WHERE id=#{id}")
	void updataStudent(Student student);
	
	@Delete("DELETE FROM student WHERE id=#{id}")
	void deleteStudent(int id);
	
	@Select("SELECT id,name,age,sex,createdate,updatadate FROM student WHERE id=#{id}")
	Student findById(@Param("id")int id);
}
